package com.he.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author He
 * @version 1.0
 * @Date 2023/9/6 15:31
 * @Desc
 */
@Configuration
public class Knife4jConfig {
    private static final String headerName = "Token";// 请求头名称

    @Bean
    public OpenAPI openApi() {
        return new OpenAPI()
                .info(new Info()
                        .title("接口文档")
                        .description("接口文档")
                        .contact(new Contact().name("he").email("508816739").url("公司官网地址"))
                        .version("v1.0"))
                .addSecurityItem(new SecurityRequirement().addList(headerName))
                .components(components());
    }

    private Components components() {
        return new Components()
                .addSecuritySchemes(
                        headerName,
                        new SecurityScheme()
                                .type(SecurityScheme.Type.APIKEY)
                                .scheme("basic")
                                .name(headerName)
                                .in(SecurityScheme.In.HEADER)
                                .description("token令牌"));
    }
}
